package com.lingx.model.impl.interpreter;

import org.springframework.stereotype.Component;

import com.lingx.model.IContext;
import com.lingx.model.IPerformer;
import com.lingx.model.impl.AbstractInterpreter;
@Component
public class DateInterpreter extends AbstractInterpreter{

	private static final long serialVersionUID = -6863638321838681629L;

	public DateInterpreter() {
		super("DateInterpreter","日期格式yyyy-MM-dd");
	}
	@Override
	public Object input(Object value) throws Exception {
		if(value!=null){
			String temp=value.toString();
			 temp=temp.replaceAll("[-]|[ ]|[:]", "");
			return temp;
		}else{
			return "";
		}
	}

	@Override
	public Object output(Object value) throws Exception {
		String temp="";
		StringBuilder sb=new StringBuilder();
		if(value!=null&&value.toString().length()>=8){
			temp=value.toString();
			sb.append(temp.substring(0, 4)).append("-").append(temp.substring(4, 6)).append("-").append(temp.substring(6, 8));
		}else{
			return value;
		}
		return sb.toString();
	}

}
